﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Windows.Navigation;
using MyPlanSilverlight.Utils;

namespace MyPlanSilverlight
{
    public partial class UserCenter : Page
    {

        private static Cache systemCache = Cache.Instance;

        public UserCenter()
        {
            InitializeComponent();
            if (systemCache["Name"] != null)
            {
                tbName.Text = "今天的努力是为了明天"; 
                //tbName.Text = systemCache["Name"].ToString();
            }

            InitMenus();
            //container.Children.Add(new RegistPage());
        }

        // 当用户导航到此页面时执行。
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {

        
        }

        private Dictionary<string, List<Menu>> menuMaps = new Dictionary<string,List<Menu>>();
        private void InitMenus()
        {
            List<Menu> teamMenus = new List<Menu>();
            teamMenus.Add(new Menu("我的小组", ""));
            teamMenus.Add(new Menu("我的任务", ""));

            menuMaps.Add("teamMenus", teamMenus);

            List<Menu> testMenus = new List<Menu>();
            testMenus.Add(new Menu("我的test", ""));
            testMenus.Add(new Menu("已完成的test", ""));

            menuMaps.Add("testMenus", testMenus);

            List<Menu> companyMenus = new List<Menu>();
            companyMenus.Add(new Menu("公司信息", "CompanyList"));
            companyMenus.Add(new Menu("创建公司", "AddCompany"));

            menuMaps.Add("companyMenus", companyMenus);
        }



        private void LoginOut_Click(object sender, RoutedEventArgs e)
        {
            systemCache.Remove("Name");
            systemCache.Remove("Account");
            this.Content = new MainPage();

        }

        private void Menu_Click(object sender, RoutedEventArgs e)
        {
           
            string key = ((HyperlinkButton)sender).Tag.ToString();
            List<Menu> menuList = menuMaps[key];

            leftNavPanel.Children.Clear();

            //<HyperlinkButton Content="会员信息" Margin="10" FontSize="20" Padding="30 5" Foreground="Black"/>
            foreach (Menu menu in menuList)
            {
                HyperlinkButton btn1 = new HyperlinkButton();
                btn1.Margin = new Thickness(10);
                btn1.Padding = new Thickness(30, 5, 0, 0);
                btn1.FontSize = 20;
                btn1.Foreground = new SolidColorBrush(Colors.Black);
                btn1.Content = menu.Name;
                btn1.Tag = menu;
                btn1.Click += NavMenu_Click;     
                leftNavPanel.Children.Add(btn1);
            }

        }

        void NavMenu_Click(object sender, RoutedEventArgs e)
        {
            Menu menu = ((HyperlinkButton)sender).Tag as Menu;
            //MessageBox.Show(menu.Name);

            if (string.IsNullOrWhiteSpace(menu.Page)) return;

            container.Children.Clear();
            if (menu.Page == "AddCompany")
            {
                container.Children.Add(new AddCompany());
            }
            else if (menu.Page == "CompanyList")
            {
                container.Children.Add(new CompanyList());
            }

        }

    }
}
